import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:getx_scaffold/getx_scaffold.dart';
import 'settings_logic.dart';
import 'routes.dart';
import '../../action/questionnaire/routes.dart';

/// 设置页面
class SettingsView extends GetView<SettingsLogic> {
  const SettingsView({super.key});

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor:  Colors.black,
      appBar: AppBar(
        backgroundColor: const Color(0xFF282528),
        elevation: 0,
        leading: GestureDetector(
          onTap: () => Get.back(),
          child: const Icon(
            Icons.arrow_back_ios,
            color: Colors.white,
            size: 20,
          ),
        ),
        title: const Text(
          '设置中心',
          style: TextStyle(
            color: Colors.white,
            fontSize: 18,
            fontWeight: FontWeight.w500,
          ),
        ),
        centerTitle: true,
      ),
      body: SingleChildScrollView(
        padding: EdgeInsets.all(24.w),
        child: Container(
          decoration: BoxDecoration(
              color: const Color(0xFF282528),
              borderRadius: BorderRadius.circular(28.r),
              border: Border.all(
                  color: Colors.white.withOpacity(0.12), width: 1.w)),
          child: Column(
            children: [
              _buildSettingItem('个人信息', Icons.person_outline,
                  () => Get.toNamed(SettingsRoutes.profile), false),
              _buildDivider(),
              _buildSettingItem('提醒设置', Icons.notifications_outlined,
                  () => Get.toNamed(SettingsRoutes.notification), false),
              _buildDivider(),
              _buildSettingItem('戒指设置', Icons.settings_outlined,
                  () => Get.toNamed(SettingsRoutes.ring), false),
              _buildDivider(),
              _buildSettingItem('戒指信息', Icons.info_outline,
                  () => Get.toNamed(SettingsRoutes.ringInfo), false),
              _buildDivider(),
              _buildSettingItem(
                  '苹果健康', Icons.favorite_outline, () => null, false),
              _buildDivider(),
              _buildSettingItem(
                  '版本管理', Icons.system_update_outlined, () => Get.toNamed(SettingsRoutes.version), false),
              _buildDivider(),
              _buildSettingItem(
                  '客服中心', Icons.headset_mic_outlined, () => null, false),
              _buildDivider(),
              _buildSettingItem('意见反馈', Icons.feedback_outlined,
                  () => Get.toNamed(SettingsRoutes.feedback), false),
              _buildDivider(),
              _buildSettingItem('用户协议', Icons.description_outlined,
                  () => Get.toNamed(QuestionnaireRoutes.questionnaire), false),
              _buildDivider(),
              _buildSettingItem(
                  '隐私政策', Icons.privacy_tip_outlined, () => null, true),
            ],
          ),
        ),
      ),
    );
  }

  Widget _buildSettingItem(
      String title, IconData icon, VoidCallback onTap, bool isLast) {
    return GestureDetector(
      onTap: onTap,
      child: Container(
        width: double.infinity,
        height: 56.h,
        padding: EdgeInsets.symmetric(horizontal: 20.w),
        child: Row(
          children: [
            // 左侧圆形图标
            Container(
              width: 32.w,
              height: 32.w,
              decoration: const BoxDecoration(
                color: Color(0xFFe6592e),
                shape: BoxShape.circle,
              ),
              child: Icon(
                icon,
                color: Colors.white,
                size: 18,
              ),
            ),
            SizedBox(width: 16.w),
            // 标题
            Expanded(
              child: Text(
                title,
                style: TextStyle(
                  color: Colors.white,
                  fontSize: 16.sp,
                  fontWeight: FontWeight.w500,
                ),
              ),
            ),
            // 右侧箭头
            const Icon(
              Icons.arrow_forward_ios,
              color: Color(0xFF666666),
              size: 16,
            ),
          ],
        ),
      ),
    );
  }

  Widget _buildDivider() {
    return Divider(
      height: 0.5.h,
      thickness: 1,
      color: Colors.white.withOpacity(0.12),
      indent: 20.w,
      endIndent: 20.w,
    );
  }
}
